package edgeprotocol

import (
	"iot-base/common/dbobj"
	"regexp"
)

//Cfg 配置协议
type Cfg struct {
	Things  []dbobj.Thing
	Station dbobj.Thing
}

//Query 查询协议
type Query struct {
	QueryType string `json:"query_type"`
	Condition string `json:"condition"`
}

//Check 检查sql注入
func (query *Query) Check() bool {
	str := `(?:')|(?:--)|(/\\*(?:.|[\\n\\r])*?\\*/)|(\b(select|update|and|or|delete|insert|trancate|char|chr|into|substr|ascii|declare|exec|count|master|into|drop|execute)\b)`
	re, err := regexp.Compile(str)
	if err != nil {
		//panic(err.Error())
		return false
	}
	return re.MatchString(query.Condition)

}
